#ifndef BUFFER_H
#define BUFFER_H

#include "host.h"

/*
 *	MsgBuf
 */
struct MsgBuf
{
	HostSub	hostSub;
	int		version;
	int		portNum;
	ULONG	packetNum;
	ULONG	command;
	int		exOffset;	// expand message offset in msgBuf
	int		dummy;
	char	msgBuf[MAX_UDPBUF];

	void Init( MsgBuf* org )
	{
		if( org == NULL )
		{
			memset( this, 0, (char*)&this->dummy - (char*)this );
			*msgBuf = 0;
			return;
		}
		memcpy( this, org, (char*)&this->dummy - (char*)this );
		strcpy_s( this->msgBuf, MAX_UDPBUF, org->msgBuf );
		strcpy_s( this->msgBuf + exOffset, MAX_UDPBUF - exOffset, org->msgBuf + exOffset );
	}
};

/*
 *	DynBuf
 */
struct DynBuf
{
	DynBuf( int size ){ _buf = (char*)malloc( _size = size ); }
	~DynBuf(){ free( _buf ); }
	char* GetBuf(){ return _buf; }
	WCHAR* GetWBuf() { return (WCHAR*)_buf; }
	int GetSize() { return _size; }

private:
	char*	_buf;
	int		_size;
};

/*
 *	RecvBuf
 */
struct RecvBuf
{
	struct sockaddr_in	addr;
	int		addrSize;
	int		size;
	char	msgBuf[MAX_UDPBUF];
};

#endif	// BUFFER_H